//
//  HLoginViewModel.m
//  HiCar
//
//  Created by 丁一 on 2019/1/28.
//  Copyright © 2019 丁一. All rights reserved.
//

#import "HLoginViewModel.h"
#import "HJonesNetting.h"

@implementation HLoginViewModel

- (instancetype)init:(id)responseObject{
    if (self = [super init]) {
        [SVProgressHUD showWithStatus:@"登录中.."];
        [HJonesNetting JonesNetting_POST:responseObject
                                 andURL:App_Login
                             andtimeout:20.0
                               finished:^(NSError * _Nonnull error, NSDictionary * _Nonnull resultDict) {
                                   if (error) {
                                       [SVProgressHUD showErrorWithStatus:@"网络加载失败"];
                                       [self.delegate Succes:0];
                                   }else{
                                       if ([[resultDict objectForKey:@"Code"] longLongValue]==1000) {
                                           
                                           [UserModel setInfo:[resultDict objectForKey:@"UserData"]];
                                           
                                           [DEFAULTS setValue:[responseObject objectForKey:@"password"] forKey:@"password"];
                                           
                                           [self.delegate Succes:1];
                                       }else{
                                           [SVProgressHUD showErrorWithStatus:[resultDict objectForKey:@"Message"]];
                                           [self.delegate Succes:0];
                                       }
                                   }
                               }
                             passmanger:^(NSURLSessionDataTask * _Nonnull manger) {
                                 
                             }
                            andprogress:^(NSProgress * _Nonnull CProgress) {
                                
                            }];
        
    }
    return self;
}

@end
